//
// Created by ct on 2020/10/30.
//

#ifndef SEALUCIA_NETTOP_RUN_H
#define SEALUCIA_NETTOP_RUN_H


#include <iostream>
#include <thread>
#include <algorithm>
#include "utils.h"
#include "cap_mgr.h"
#include "proc.h"
#include "name_res.h"
#include "settings.h"
#include "epoll_stdin.h"

namespace nettop {
    static bool quit = false;
    // 线程间共享数据
    // 这是一个单例模式对象
    class nettop_mgr {
    public:
        nettop::packet_list p_list;
        nettop::cap_mgr			c;
        nettop::local_addr_mgr lam;
        nettop::async_log_list log_list;
    public:
        // 实例化全局单例对象
        static nettop_mgr& Instance();
    };

    // data format
    class curses_setup {
        static char BPS[] ,
                KBPS[],
                MBPS[],
                GBPS[];

        static void recv_send_format(const std::chrono::nanoseconds &tm_elapsed, const size_t recv, const size_t sent,
                                     double &recv_d, double &sent_d, const char *&fmt) ;
    public:
        explicit curses_setup() = default;

        static void redraw(const std::chrono::nanoseconds &tm_elapsed, nettop::ps_vec &ps_v, const nettop::proc_mgr::stats &st);
        static std::string format_proc(const std::chrono::nanoseconds &tm_elapsed, nettop::ps_vec &ps_v, const nettop::proc_mgr::stats &st);

    };


}
#endif //SEALUCIA_NETTOP_RUN_H
